using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace CommerceForUmbraco.xsltExtensions
{
	/// <summary>
	/// Strongly-typed collection for the ProductMetum class.
	/// </summary>
	[Serializable]
	public partial class ProductMetumCollection : ActiveList<ProductMetum, ProductMetumCollection> 
	{	   
		public ProductMetumCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the ProductMeta table.
	/// </summary>
	[Serializable]
	public partial class ProductMetum : ActiveRecord<ProductMetum>
	{
		#region .ctors and Default Settings
		
		public ProductMetum()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public ProductMetum(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public ProductMetum(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public ProductMetum(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("ProductMeta", TableType.Table, DataService.GetInstance("XsltExt"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarProductMetaId = new TableSchema.TableColumn(schema);
				colvarProductMetaId.ColumnName = "productMetaId";
				colvarProductMetaId.DataType = DbType.Int32;
				colvarProductMetaId.MaxLength = 0;
				colvarProductMetaId.AutoIncrement = true;
				colvarProductMetaId.IsNullable = false;
				colvarProductMetaId.IsPrimaryKey = true;
				colvarProductMetaId.IsForeignKey = true;
				colvarProductMetaId.IsReadOnly = false;
				colvarProductMetaId.DefaultSetting = @"";
				
					colvarProductMetaId.ForeignKeyTableName = "ProductMeta";
				schema.Columns.Add(colvarProductMetaId);
				
				TableSchema.TableColumn colvarProductId = new TableSchema.TableColumn(schema);
				colvarProductId.ColumnName = "productId";
				colvarProductId.DataType = DbType.Int32;
				colvarProductId.MaxLength = 0;
				colvarProductId.AutoIncrement = false;
				colvarProductId.IsNullable = true;
				colvarProductId.IsPrimaryKey = false;
				colvarProductId.IsForeignKey = false;
				colvarProductId.IsReadOnly = false;
				colvarProductId.DefaultSetting = @"";
				colvarProductId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProductId);
				
				TableSchema.TableColumn colvarProductGUID = new TableSchema.TableColumn(schema);
				colvarProductGUID.ColumnName = "productGUID";
				colvarProductGUID.DataType = DbType.Guid;
				colvarProductGUID.MaxLength = 0;
				colvarProductGUID.AutoIncrement = false;
				colvarProductGUID.IsNullable = true;
				colvarProductGUID.IsPrimaryKey = false;
				colvarProductGUID.IsForeignKey = false;
				colvarProductGUID.IsReadOnly = false;
				colvarProductGUID.DefaultSetting = @"";
				colvarProductGUID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProductGUID);
				
				TableSchema.TableColumn colvarHtmlTitle = new TableSchema.TableColumn(schema);
				colvarHtmlTitle.ColumnName = "htmlTitle";
				colvarHtmlTitle.DataType = DbType.String;
				colvarHtmlTitle.MaxLength = 500;
				colvarHtmlTitle.AutoIncrement = false;
				colvarHtmlTitle.IsNullable = true;
				colvarHtmlTitle.IsPrimaryKey = false;
				colvarHtmlTitle.IsForeignKey = false;
				colvarHtmlTitle.IsReadOnly = false;
				colvarHtmlTitle.DefaultSetting = @"";
				colvarHtmlTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHtmlTitle);
				
				TableSchema.TableColumn colvarHtmlDescription = new TableSchema.TableColumn(schema);
				colvarHtmlDescription.ColumnName = "htmlDescription";
				colvarHtmlDescription.DataType = DbType.String;
				colvarHtmlDescription.MaxLength = 4000;
				colvarHtmlDescription.AutoIncrement = false;
				colvarHtmlDescription.IsNullable = true;
				colvarHtmlDescription.IsPrimaryKey = false;
				colvarHtmlDescription.IsForeignKey = false;
				colvarHtmlDescription.IsReadOnly = false;
				colvarHtmlDescription.DefaultSetting = @"";
				colvarHtmlDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHtmlDescription);
				
				TableSchema.TableColumn colvarHtmlKeywords = new TableSchema.TableColumn(schema);
				colvarHtmlKeywords.ColumnName = "htmlKeywords";
				colvarHtmlKeywords.DataType = DbType.String;
				colvarHtmlKeywords.MaxLength = 4000;
				colvarHtmlKeywords.AutoIncrement = false;
				colvarHtmlKeywords.IsNullable = true;
				colvarHtmlKeywords.IsPrimaryKey = false;
				colvarHtmlKeywords.IsForeignKey = false;
				colvarHtmlKeywords.IsReadOnly = false;
				colvarHtmlKeywords.DefaultSetting = @"";
				colvarHtmlKeywords.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHtmlKeywords);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["XsltExt"].AddSchema("ProductMeta",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ProductMetaId")]
		public int ProductMetaId 
		{
			get { return GetColumnValue<int>("productMetaId"); }

			set { SetColumnValue("productMetaId", value); }

		}

		  
		[XmlAttribute("ProductId")]
		public int? ProductId 
		{
			get { return GetColumnValue<int?>("productId"); }

			set { SetColumnValue("productId", value); }

		}

		  
		[XmlAttribute("ProductGUID")]
		public Guid? ProductGUID 
		{
			get { return GetColumnValue<Guid?>("productGUID"); }

			set { SetColumnValue("productGUID", value); }

		}

		  
		[XmlAttribute("HtmlTitle")]
		public string HtmlTitle 
		{
			get { return GetColumnValue<string>("htmlTitle"); }

			set { SetColumnValue("htmlTitle", value); }

		}

		  
		[XmlAttribute("HtmlDescription")]
		public string HtmlDescription 
		{
			get { return GetColumnValue<string>("htmlDescription"); }

			set { SetColumnValue("htmlDescription", value); }

		}

		  
		[XmlAttribute("HtmlKeywords")]
		public string HtmlKeywords 
		{
			get { return GetColumnValue<string>("htmlKeywords"); }

			set { SetColumnValue("htmlKeywords", value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>("createdOn"); }

			set { SetColumnValue("createdOn", value); }

		}

		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>("createdBy"); }

			set { SetColumnValue("createdBy", value); }

		}

		  
		[XmlAttribute("ModifiedOn")]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>("modifiedOn"); }

			set { SetColumnValue("modifiedOn", value); }

		}

		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>("modifiedBy"); }

			set { SetColumnValue("modifiedBy", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public CommerceForUmbraco.xsltExtensions.ProductMetumCollection ChildProductMeta()
		{
			return new CommerceForUmbraco.xsltExtensions.ProductMetumCollection().Where(ProductMetum.Columns.ProductMetaId, ProductMetaId).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a ProductMetum ActiveRecord object related to this ProductMetum
		/// 
		/// </summary>
		public CommerceForUmbraco.xsltExtensions.ProductMetum ParentProductMetum
		{
			get { return CommerceForUmbraco.xsltExtensions.ProductMetum.FetchByID(this.ProductMetaId); }

			set { SetColumnValue("productMetaId", value.ProductMetaId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varProductId,Guid? varProductGUID,string varHtmlTitle,string varHtmlDescription,string varHtmlKeywords,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			ProductMetum item = new ProductMetum();
			
			item.ProductId = varProductId;
			
			item.ProductGUID = varProductGUID;
			
			item.HtmlTitle = varHtmlTitle;
			
			item.HtmlDescription = varHtmlDescription;
			
			item.HtmlKeywords = varHtmlKeywords;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varProductMetaId,int? varProductId,Guid? varProductGUID,string varHtmlTitle,string varHtmlDescription,string varHtmlKeywords,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			ProductMetum item = new ProductMetum();
			
				item.ProductMetaId = varProductMetaId;
				
				item.ProductId = varProductId;
				
				item.ProductGUID = varProductGUID;
				
				item.HtmlTitle = varHtmlTitle;
				
				item.HtmlDescription = varHtmlDescription;
				
				item.HtmlKeywords = varHtmlKeywords;
				
				item.CreatedOn = varCreatedOn;
				
				item.CreatedBy = varCreatedBy;
				
				item.ModifiedOn = varModifiedOn;
				
				item.ModifiedBy = varModifiedBy;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ProductMetaId = @"productMetaId";
			 public static string ProductId = @"productId";
			 public static string ProductGUID = @"productGUID";
			 public static string HtmlTitle = @"htmlTitle";
			 public static string HtmlDescription = @"htmlDescription";
			 public static string HtmlKeywords = @"htmlKeywords";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
	}

}

